﻿package 
{
	import flash.display.*;
	import flash.net.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.*;
	public class LoveCD extends Sprite
	{
		private var radius:Number;
		private var _bitmap:Bitmap;
		private var shapeB:Shape;
		private var maskShape:Shape;
		public function LoveCD()
		{	
			 
		}	
		
		
		public function init():void
		{
			drawBase();
			
			shapeB=new Shape();
			shapeB.x=0;
			shapeB.y=0;
			addChild(shapeB);
			
			maskShape=new Shape();
			maskShape.x=0;
			maskShape.y=0;
			addChild(maskShape);
			
		}
		
		//设置外圆半径参数
		public function set radius(value:Number):void
		{
			this.radius=value;
		}
		
		public function get radius():Number
		{
			return this.radius;
		}
		
		//绘制底部
		private function drawBase():void
		{
			var bottomShape:Shape=new Shape();
			bottomShape.x=0;
			bottomShape.y=0;
			addChild(bottomShape);
			bottomShape.graphics.beginFill(0xffffff,0.5);
			bottomShape.graphics.drawCircle(0,0,radius);
			bottomShape.graphics.drawCircle(0,0,radius-2);
			bottomShape.graphics.endFill();			
		}
		
		private function onLoadComplete(event:Event):void
		{
			event.currentTarget.removeEventListener(Event.COMPLETE,onLoadComplete);
			var bitmap:Bitmap=Bitmap(event.currentTarget.content);
			drawBase();	
			this.content=bitmap;	
			this.dispatchEvent(new Event(LoveCD.LOAD_COMPLETE));	     
		}
		
		//设置位图
		public function set content(value:Bitmap):void
		{
			this._bitmap=value;
			
		}
		public function get content():Bitmap
		{
			return this._bitmap;
		}
		
		//绘制CD,radiusA,radiusB,radiusC，由小到大
		public function drawCD(image:Bitmap,radiusA:Number,radiusB:Number,radiusC:Number,offPoint:Point=null,repeat:Boolean=false,smooth:Boolean=false):void
		{
			
			if(offPoint==null)		
			 maskShape.graphics.beginBitmapFill(image.bitmapData,null,repeat,smooth);
			else
			 maskShape.graphics.beginBitmapFill(image.bitmapData,new Matrix(1,0,0,1,offPoint.x,offPoint.y),repeat,smooth);
			
			maskShape.graphics.drawCircle(0,0,radiusA);
			maskShape.graphics.drawCircle(0,0,radius-2);
			maskShape.graphics.endFill();
			
			
			shapeB.graphics.beginFill(0x999999,0.3);
			shapeB.graphics.lineStyle(0,0x999999);
			shapeB.graphics.drawCircle(0,0,radiusB);
			shapeB.graphics.drawCircle(0,0,radiusB+2);
			shapeB.graphics.drawCircle(0,0,radiusC);
			shapeB.graphics.endFill();
			
			shapeB.graphics.lineStyle(0,0xffffff,0.6);
			shapeB.graphics.drawCircle(0,0,radiusC-1);
		}
		
		
		 /*
		  * 清除图形信息
		 */
		public function clear():void
		{
			maskShape.graphics.clear();
			shapeB.graphics.clear();		
		}
		
		
		//移动位置
		public function move(x:Number,y:Number):void
		{
			this.x=x;
			this.y=y;
		}
		
	}
}